package com.example.faqdemo.controller;

import com.example.faqdemo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/login")
public class LoginController {
    @Autowired
    private UserService userService;

    @PostMapping
    public String login(@RequestParam String username, @RequestParam String password) {
        User user = userService.findByUsername(username);
        if (user != null && user.getPassword().equals(password)) {
            return "登录成功，用户类型：" + (user.getType() == 1 ? "管理员" : "普通用户");
        } else {
            return "用户名或密码错误";
        }
    }
}